1, #!/bin/shThe first line tells the operating system that the interpreter for this script is/bin/sh this executable file2. While loop:#!/bin/shSleep 1; echo "User"; \Sleep 1; echo "Password"; \While true; Do \echo "Output"Sleep 1; \Done3, the shell script realizes the automatic input of Telnet, implements with the pipeline, the last while loop is used to give the last command full execution time(Sleep 1; echo "user"; \Sleep 1; echo "Password"; \Sleep
Integer two-dollar comparison operator
The comparer used in [] and test
The comparer used in (()) and [[]]
Description
-eq
= = or =
Equal abbreviations, equal
-ne
!=
Not equal abbreviations, unequal
-gt
>
Greater than greater than
-ge
>=
Greater than or equal to greater equal
-lt
Less than than similar
-le
Less than or equal to
Shell Script Introduction
Shell is a scripting language
You can use logical judgments, loops, and other syntax
Functions can be custom-defined
The shell is a collection of system commands
Shell scripts enable automated operations, which can greatly i
This article collects a bunch of shell scripting tricks, I said, I write a blog mainly to make some learning notes to facilitate their own review, so I will make such an article, there is nothing incomprehensible. About the origin of these techniques, eh, I also forget, may come from Theunixschool, Commandlinefu, cool and igigo.net, of course, there are some of my own experience, tube him, into my brain is
I. Introduction of ExpectExpect is a simple TCL-based scripting language tool, a software suite that enables automatic interaction, with the function of automating human-computer interaction, and the ability to "session" with an interactive program in a way that is set in the script content. Depending on the content of the script, expect can tell what the program will prompt or feedback and what is the correct answer; it is an explanatory
Reprinted from: http://www.92csz.com/study/linux/12.htm The basics before you learn Shell scriptingA shell script is essential for everyday Linux system management, and if you don't write a shell script, you're not a qualified administrator. At present, many organizations in the recruitment of Linux system administrators, She
First, using the For loop structureTarget:This case requires writing a shell script chkhosts.sh that uses a for loop to detect the surviving status of multiple hosts, with the following requirements and instructions:1> Ping Detection of 192.168.4.0/24 network segments2> Ping Detection can refer to the pinghost.sh script of the preceding dayThe 3> script can traverse the ping hosts and feed back the surviving statusAfter the test script is executed, th
Simonsu
Blog
Comment Wall
Reader Wall
Link
About
The SH scripting syntax in LinuxPlaying Linux all know the convenience of SH script, but how to write sh script is a novice and rookie problem like me. It is one thing to be able to write, and not to know is another. Holding a good study, the spirit of day up, we have time to see it, no harm. Here's a copy of a large section of the SH script's syntax description. Look slowl
script rotatefile can solve this problem. This script can rename the message to save the file (assuming outmail) is OUTMAIL.1, and for outmail.1 it becomes outmail.2 and so on ...
The code is as follows:
#!/bin/sh
# vim: set sw=4 ts=4 et:
ver="0.1"
help()
{
cat
How does this script work? After detecting a file name provided by the user, we perform a 9 to 1 loop. File 9 is named 10, file 8 is renamed to 9, and so on. After the loop is complete, we name the original file 1
# input Check:If [-Z ']; ThenError "Error:you must specify a file, use-h for help"FiFilen= "$"# Rename any. 1,. 2 etc File:For N in 9 8 7 6 5 4 3 2 1; DoIf [-F ' $filen. $n "]; Thenp= ' expr $n + 1 'echo "MV $filen. $n $filen. $p"MV $filen. $n $filen. $pFiDone# Rename the original file:If [-F "$filen"]; Thenecho "MV $filen $filen. 1"MV $filen $filen. 1Fiecho Touch $filenTouch $filenHow does this script work? After detecting a file name provided by the user, we perform a 9 to 1 loop. File 9 is na
use it as the first command option. The FS parameter immediately following the-F option is a regular expression or is provided as the next argument. The field separator character can also be set to be specified using the built-in variable FS. Such as:Awk-f ' \ t ' {...} ' files fs= ' [\f\v] ' filesAbove example the value set by the-F option is applied to the first filegroup, and the value specified by FS is applied to the second group. The-v option initialized must be placed before any programs
Try to make your work more efficient, write scripts, and use scripts, often with less effort. So, take some time today to learn about shell scripting.--------------ahead of the high-energy warning, this article is written slightly entertain, if you have to look uncomfortable, please go to the top right corner----------------------The shell has two ways of executi
1. Linux Scripting Basics1.1 Basic Introduction to grammar1.1.1 StartThe program must start with the following line (must be placed on the first line of the file):#!/bin/shThe symbolic #! is used to tell the system that the parameters behind it are the programs used to execute the file. In this example we use/BIN/SH to execute the program.When you edit a good script, you must also make it executable if you want to execute the script.To make the script
Student's score is 0-100, please enter again! [[emailprotected]shell]#shtest7.sh Please enter student's score: dagfag This is not a number please enter it again!! [[emailprotected]shell]#shtest7.sh Please enter student's score: 89 good!Using the example above can see the use of case judgment, although the example is not very good, but a more comprehensive practice
Some good habits of shell scripting
1. Naming rules
The script name ends with. SH, and names are as famous as possible. Here are a few of the script naming styles that are available for reference. Through the following fresh and refined style, readers can easily understand the role of the script.clearlog.sh clearlog.sh clearsql.sh snmp_install.sh monitor.sh
2.
overwritten.Syntax for input redirection: directives Example: For example, we have a file Test.txt with 3 lines of content. We want to count his number of rows, which can be counted by executing commands: Wc-l Result output: 3Well, through the content of section four, we have mastered the basic use of the shell, can write some simple shell program, but there is a gap between the real coding, so we have to
Tags: shell scriptOne, Shell scriptScript: Can execute the file, after running can implement some function (command stack, non-interactive)Standardize the general composition of shell scripts#! Environmental Statement (Sha-bang)# comment TextExecutable codeSecond, simply write a shell script, according to international
0. IntroductionPrepare to open a new pit and update a shell practice every day. Because shell scripts belong to the kind of skills that are unfamiliar or even forgotten when you're not practicing, I can only keep on practicing in order to resist the drag of forgetting.1. First day Practice topicsTopicPlease generate a
Getting Started with Shell scripting--NextThis article introduces the following: Logical operators (, | 、!、 ^), test commands, script execution procedures1. Logical operators(1) and short circuit andTrue, False1 0And:1 1 = 11 0 = 00 1 = 00 0 = 0For , if the left condition is false, the value of the right condition is also evaluated. Features as long as a false is assumed to be falseShort Circuit with:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.